/**
 *
 */
package com.ssyt.examinationsystem.dao.impl;

import com.jdbc.util.JdbcUtils;
import com.ssyt.examinationsystem.dao.ICourseInfoDAO;
import com.ssyt.examinationsystem.entity.CourseInfo;
import com.ssyt.examinationsystem.util.CollectionUtils;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class CourseInfoDAOImpl implements ICourseInfoDAO {

    @Override
    public List<Map<String, Object>> getCourseInfos() {
        String sql = "select * from courseInfo";
        return JdbcUtils.executeQuery(sql);
    }

    @Override
    public int addCourseInfo(CourseInfo course) {
        String sql = "insert into courseInfo values(null,?)";
        return JdbcUtils.executeUpdate(sql, course.getCourseName());
    }

    @Override
    public int deleteCourseInfo(String courseId) {
        String sql = "delete from courseInfo where courseId=?";
        return JdbcUtils.executeUpdate(sql, courseId);
    }

    @Override
    public Map<String, Object> getCourseInfoByRoleId(String courseId) {
        String sql = "select * from courseInfo where courseId=?";
        List<Map<String, Object>> list = JdbcUtils.executeQuery(sql, courseId);
        return CollectionUtils.isEmptyForList(list) ? list.get(0) : null;
    }

    @Override
    public int updateCourseInfo(CourseInfo course) {
        String sql = "update courseInfo set coursename=? where courseId=?";
        Object[] parameters = {course.getCourseName(), course.getCourseId()};

        return JdbcUtils.executeUpdate(sql, parameters);
    }

}
